package com.ihr360.payroll.service.salaryplan;

import com.ihr360.commons.specification.Ihr360Specification;
import com.ihr360.entity.BasicStaffInfoEntity;
import com.ihr360.entity.BasicStaffInfoInSalaryPlanEntity;
import com.ihr360.payroll.model.dto.salary.plan.SalaryPlanStaff;
import com.ihr360.shared.basicstaffinfo.dto.SyncedBasicStaffInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;

import java.util.List;
import java.util.Map;

/**
 * @author tomtao
 */
public interface SalaryPlanStaffService {

    /**
     * 排量保存
     *
     * @param salaryPlanStaffs
     * @return
     */
    List<SalaryPlanStaff> save(Long planId,List<SalaryPlanStaff> salaryPlanStaffs);

    /**
     * 保存
     *
     * @param salaryPlanStaff
     * @return
     */
    SalaryPlanStaff save(Long planId,SalaryPlanStaff salaryPlanStaff);

    /**
     * 修改工资单
     *
     * @param salaryPlanId
     * @param staffId
     * @param paySlipConfigId
     * @return
     */
    SalaryPlanStaff changePaySlipConfig(Long salaryPlanId, String staffId, Long paySlipConfigId);

    /**
     * 将指定员工添加到方案中
     * Note: staffIdList对应员工的状态只能是TEMP_REMOVE或者还未添加到方案中
     * 方案中临时删除状态（TEMP_REMOVFE）的员工切换到正常状态（NORMAL）
     * 方案中不存在的员工只能以临时添加状态（TEMP_ADD）插入
     *
     * @param planId
     * @param staffIdList
     */
    void dummyAddStaff2Plan(Long planId, List<String> staffIdList);

    /**
     * 删除员工
     *
     * @param planId
     * @param staffIdList
     */
    void deleteSalaryPlanStaff(Long planId, List<String> staffIdList);

    /**
     * 删除薪资方案中的员工
     * Note: staffIdList对应员工的状态只能是TEMP_ADD或者NORMAL
     * 如果方案中的员工：状态为临时添加(TEMP_ADD)，则直接移除该员工；
     * 状态为正常(NORMAL)，则将该员工状态切换为临时删除(TEMP_REMOVE)
     *
     * @param planId
     * @param staffIdList
     */
    void dummyDeleteSalaryPlanStaff(Long planId, List<String> staffIdList);

    /**
     * 重置方案中的员工状态
     * TEMP_ADD 的数据移除
     * TEMP_REMOVFE 的数据重置为NORMAL
     *
     * @param planId
     */
    void resetSalaryPlanStaffStatus(Long planId);

    /**
     * 分页获取薪资方案中包含的员工
     * staffState为NORMAL和TEMP_REMOVE;
     *
     * @param companyId
     * @param planId
     * @param specification
     * @param pageable
     * @return
     */
    Page<BasicStaffInfoInSalaryPlanEntity> getStaffs4SalaryPlan(String companyId, Long planId,
                                                                Specification<SyncedBasicStaffInfo> specification,
                                                                Pageable pageable);

    /**
     * 分页获取账期中包含的员工
     * staffState为NORMAL和TEMP_ADD;
     *
     * @param companyId
     * @param planId
     * @param specification
     * @param pageable
     * @return
     */
    Page<BasicStaffInfoEntity> getStaffs4ActivePayPeriod(String companyId, Long planId,
                                                         Ihr360Specification<SyncedBasicStaffInfo> specification,
                                                         Pageable pageable);

    /**
     * 根据多个状态获取方案关联员工
     *
     * @param salaryPlanId
     * @param staffStatusList
     * @return
     */
    List<SalaryPlanStaff> getListBySalaryPlanIdAndStaffStates(Long salaryPlanId, List<Integer> staffStatusList);

    /**
     * 根据员工Id获取对应的方案名称
     *
     * @param staffIdList
     * @return
     */
    Map<String, List<String>> getStaffNameAndStaffIdMapByStaffIdList(List<String> staffIdList);

}
